package com.leyou.contrlloer;

import com.leyou.dto.SpecGroupDTO;
import com.leyou.dto.SpecParamDTO;
import com.leyou.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.CollectionUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class SpecController {

    @Autowired
    SpecService specService;

    @GetMapping("/spec/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> findSpecGroupByCid(@RequestParam("id") Long cid) {
        List<SpecGroupDTO> specGroupDTOList = specService.findSpecGroupByCid(cid);
        return ResponseEntity.ok(specGroupDTOList);
    }

    @GetMapping("/spec/params")
    ResponseEntity<List<SpecParamDTO>> findSpecParam(@RequestParam(name = "gid", required = false) Long gid,
                                                     @RequestParam(name = "cid", required = false) Long cid,
                                                     @RequestParam(name = "search", required = false) Boolean search) {
        List<SpecParamDTO> specParam = specService.findSpecParam(gid, cid, search);
        return ResponseEntity.ok(specParam);
    }



}
